package controller

import (
	"gin/response"
	"gin/service"
	"gin/validate"
	"github.com/gin-gonic/gin"
)

func HealthyReturn(ctx *gin.Context) {
	response.Success(ctx, nil, "Server connection health.")
}

func GenerateToken(ctx *gin.Context) {
	var generateToken validate.GenerateToken
	err := ctx.ShouldBindJSON(&generateToken)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	accessKey, secretKey, errService := service.GenerateToken()

	if errService != nil {
		response.Fail(ctx, nil, errService.Error())
		return
	}

	response.Success(ctx, gin.H{"access_key": accessKey, "secret_key": secretKey}, "Token generated successfully.")
}

func GetToken(ctx *gin.Context) {
	var getToken validate.GetToken
	err := ctx.ShouldBindJSON(&getToken)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	accessKey, secretKey, errService := service.GetToken()

	if errService != nil {
		response.Fail(ctx, nil, errService.Error())
		return
	}

	response.Success(ctx, gin.H{"access_key": accessKey, "secret_key": secretKey}, "Token query successfully.")
}
